﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 泛型链表
{
    class Program
    {
        static void Main(string[] args)
        {
            //var list1 = new LinkedList<int>();

            //list1.AddLast(2);
            //list1.AddLast(4);
            //list1.AddLast(6);


            //foreach (int i in list1)
            //{
            //    Console.WriteLine(i);
            //}
            StaticDemo<int>.x = 4;
            StaticDemo<string>.x = 5;

            StaticDemo<int>.x = 40;

            Console.WriteLine(StaticDemo<string>.x);
            Console.ReadKey();
        }
    }

    public class LinkedListNode<T>
    {
        public LinkedListNode(T value)
        {
            this.Value = value;
        }
        public T Value { get; private set; }

        public LinkedListNode<T> Next { get; internal set; }

        public LinkedListNode<T> Prev { get; internal set; }
    }

    public class LinkedList<T> : IEnumerable<T>
    {
        public LinkedListNode<T> First { get; private set; }

        public LinkedListNode<T> Last { get; private set; }
        public LinkedListNode<T> AddLast(T  node)
        {
            var newNode = new LinkedListNode<T>(node);
            if (First == null)
            {
                First = newNode;
                newNode.Prev = Last;
                Last = First;
            }
            else
            {
                LinkedListNode<T> previous = Last;
                Last.Next = newNode;
                Last = newNode;
                Last.Prev = previous;
            }

            return newNode;
        }

        public IEnumerator<T> GetEnumerator()
        {
            LinkedListNode<T> current = First;
            while (current != null)
            {
                yield return current.Value;
                current = current.Next;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }

    public abstract  class Calc<T>
    {
        public abstract T Add(T x,T y);
       
        public abstract T Sub(T x,T y);
    }
    public class IntCalc:Calc<int>
    {
        public override int Add(int x, int  y)
    {
        return x+y;
    }
        public override int Sub(int x, int y)
        {
            return x - y;
        }
    }

    public class StaticDemo<T>
    {
        public static int x;
    }
}
